define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    tuikuan_url: 'order/tuikuan_url',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.name', title: __('购买人')},
                        {field: 'address.school', title: __('上课学校')},
                        {field: 'teacher.name', title: __('上课教师')},
                        {field: 'club_name', title: __('社团')},
                        {field: 'sign_type', title: __('签约类型')},
                        {
                            field: 'dtl_info',
                            title: __('签约数据'),
                            operate: false,
                            formatter: function (value,row,index,field) {
                                if(index < 4){
                                    return "<span style='display: block;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;' data-toggle='tooltip' data-placement='bottom' title='"+row.dtl_info+"'>" + value + "</span>";
                                }else{
                                    return "<span style='display: block;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;' data-toggle='tooltip' title='"+row.dtl_info+"'>" + value + "</span>";
                                }
                            },
                            cellStyle: function (value,row,index,field) {
                                return {
                                    css:{
                                        "white-space":"nowrap",
                                        "text-overflow":"ellipsis",
                                        "overflow":"hidden",
                                        "max-width":"250px",
                                    }
                                };
                            }
                        },
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                        {field: 'sanfang', title: __('Sanfang'), operate: 'LIKE'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {
                            field: 'pay_status',
                            title: __('Pay_status'),
                            operate: '=',
                            searchList: Config.getPayStatus,
                            defaultValue: "",
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'type', title: __('Type'), operate: 'LIKE'},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name:"tuikuan",
                                    title:__("退款"),
                                    text:__("退款"),
                                    classname:"btn btn-xs btn-info btn-dialog",
                                    icon:"fa fa-push",
                                    url: 'order/tuikuan',
                                    visible: function (row) {
                                        if (row.pay_status == 2) {
                                            return true;
                                        } else {
                                            return false;
                                        }
                                    },
                                    refresh: true
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        tuikuan: function(){
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
